// pages/agreement_management/agreement_management.js
var util = require('../../utils/util');
var App = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        date: '',//传入时间
        date_month: '',//显示时间
        // store_name: ['全部', '潜客跟进', '会员跟进'],
        oder:[],
        page: 1,
        limit: 10
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var This = this;
        var time = util.formatTime(new Date());
        var date_value = time.slice(0, 4) + "-" + time.slice(5, 7)
        var date_value_month = time.slice(0, 4) + "-" + time.slice(5, 7)
        This.setData({
            date: date_value,
            date_month: date_value_month,
            // genj: This.data.store_name[0],

        }) 
        This.loga();
    },
    bindDateChange: function (e) {
        var This = this;
        This.setData({
            information_list: []
        })
        var date_month = e.detail.value
        var year = date_month.slice(0, 4)
        var month = date_month.slice(5, 7)
        var date_time = year + '-' + month
        This.setData({
            date_month: date_time,
            date: e.detail.value
        })
        console.log(This.data.date_month)
        this.loga();
    },
    //列表协议
    loga:function(e){
        var This = this;
      App._get('coach/Agreement/new_get_agreement_list', {
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            store_id: wx.getStorageSync('store_id'),
            date_str: This.data.date_month,
            page: This.data.page,
            limit: This.data.limit
        }, function (res) {
            if(res.status == 1){
                if(res.list.length >0){
                    for (var index in res.list){
                        This.data.oder.push(res.list[index])
                    }
                    This.setData({
                        oder: This.data.oder
                    })
                }else{
                    if (This.data.page == 1){
                        This.setData({
                            oder: res.list
                        })
                    }else {
                        wx.showToast({
                            title: '加载到底部',
                            icon: 'none',
                            duration: 1000
                        })
                        This.setData({
                            oder: This.data.oder
                        })
                    } 
                }
            }else{
                wx.showToast({
                    title: res.error,
                    icon:'none',
                    duration: 2000
                })
            }
        })
    },
    //跳转协议
    to_xy:function(e){
        console.log(e)
        var This = this;
        wx.navigateTo({
            url: '../agreement/agreement?id=' + e.currentTarget.dataset.id,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var This = this;
        This.setData({
            page:This.data.page+1
        })
        This.loga();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})